package com.zzyl;



import com.zzyl.mapper.ReservationMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;

import java.time.LocalDateTime;
@Component
@Slf4j
@RequiredArgsConstructor
public class MyTask1 {
    
    private final ReservationMapper reservationMapper;
   
    /*
    * 定时任务，预约自动过期
    * */
    // 每小时的16分钟执行
    @Scheduled(cron = "0 16 * * * ?")
    public void checkAppointmentsAt16Minutes() {
        // 检查并更新过时预约的逻辑
        updateReservationStatus();
        System.out.println("定时任务每小时16分钟已更新");
    }

    // 每小时的46分钟执行
    @Scheduled(cron = "0 46 * * * ?")
    public void checkAppointmentsAt46Minutes() {
        // 检查并更新过时预约的逻辑
        updateReservationStatus();
        System.out.println("定时任务每小时16分钟已更新");
    }
    
    /*
    迟到超过15分钟，就需要将预约状态调整为已过期
    * */
    public void updateReservationStatus() {
        /*
        * LocalDateTime.now().minusMinutes(15);
        * 拿到当前时间并往后推15分钟
        * */
        LocalDateTime localDateTime = LocalDateTime.now().minusMinutes(15);
        reservationMapper.updateReservationStatus(localDateTime);
    }
}
